package com.itheima.reggie.comon;

import lombok.Data;

import java.io.Serializable;

@Data
public class ResultInfo<T> implements Serializable {
    //一个码 1:代表成功 0:代表失败
    private Integer code;
    //失败的原因
    private String msg;
    //成功的数据
    private T data;

    //成功
    public static <T> ResultInfo<T> success(T obj) {
        ResultInfo<T> resultInfo = new ResultInfo<>();
        resultInfo.code = 1;
        resultInfo.data = obj;
        return resultInfo;
    }

    //失败
    public static <T> ResultInfo<T> error(String msg) {
        ResultInfo<T> resultInfo = new ResultInfo<>();
        resultInfo.code = 0;
        resultInfo.msg = msg;
        return resultInfo;
    }
}
